package com.zoffy.wmsbackend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zoffy.wmsbackend.common.BaseResponse;
import com.zoffy.wmsbackend.common.CommonObj;
import com.zoffy.wmsbackend.common.RequestParam;
import com.zoffy.wmsbackend.common.ResultUtils;
import com.zoffy.wmsbackend.model.dto.materialUsagePlan.MaterialPlanAddDto;
import com.zoffy.wmsbackend.model.dto.materialUsagePlan.MaterialUsagePlanDto;
import com.zoffy.wmsbackend.model.vo.materialUsagePlan.MaterialUsagePlanDetailsVo;
import com.zoffy.wmsbackend.model.vo.materialUsagePlan.MaterialUsagePlanVo;
import com.zoffy.wmsbackend.service.MaterialUsagePlanService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/materialUsagePlan")
public class MaterialUsagePlanController {

    @Resource
    private MaterialUsagePlanService materialUsagePlanService;

    @PostMapping("/list")
    public BaseResponse<Page<MaterialUsagePlanVo>> listMaterialUsagePlanByPage(@RequestBody RequestParam<MaterialUsagePlanDto> requestParam) {
        Page<MaterialUsagePlanVo> res = materialUsagePlanService.listMaterialUsagePlanVoByPage(requestParam);
        return ResultUtils.success(res);
    }

    @PostMapping("/add")
    public BaseResponse<Boolean> addMaterialUsagePlan(@RequestBody MaterialPlanAddDto materialPlanAddDto) {
        Boolean res = materialUsagePlanService.addMaterialUsagePlan(materialPlanAddDto);
        return ResultUtils.success(res);
    }
    @PostMapping("/approval")
    public BaseResponse<Boolean> approval(@RequestBody CommonObj<Long> materialUsagePlanId) {
        Long id = materialUsagePlanId.getData();
        Boolean res = materialUsagePlanService.approval(id);
        return ResultUtils.success(res);
    }

    // 模仿 StockOutController 的 getDetailsById 方法
    @GetMapping("/")
    public BaseResponse<MaterialUsagePlanDetailsVo> getDetailsById(@org.springframework.web.bind.annotation.RequestParam("id") Long id) {
        MaterialUsagePlanDetailsVo res = materialUsagePlanService.getDetailsById(id);
        return ResultUtils.success(res);
    }
}